home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / Win_ent.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  32.2 KB  |  1,391 lines

  1. #include "stdafx.h"
  2. #include "qe3.h"
  3. #include "entityw.h"
  4. #include "TexWnd.h"
  5. #include "WaveOpen.h"
  6.  
  7. int rgIds[EntLast] = {
  8.     IDC_E_LIST,
  9.     IDC_E_COMMENT,
  10.     IDC_CHECK1,
  11.     IDC_CHECK2,
  12.     IDC_CHECK3,
  13.     IDC_CHECK4,
  14.     IDC_CHECK5,
  15.     IDC_CHECK6,
  16.     IDC_CHECK7,
  17.     IDC_CHECK8,
  18.     IDC_CHECK9,
  19.     IDC_CHECK10,
  20.     IDC_CHECK11,
  21.     IDC_CHECK12,
  22.     IDC_E_PROPS,
  23.     IDC_E_0,
  24.     IDC_E_45,
  25.     IDC_E_90,
  26.     IDC_E_135,
  27.     IDC_E_180,
  28.     IDC_E_225,
  29.     IDC_E_270,
  30.     IDC_E_315,
  31.     IDC_E_UP,
  32.     IDC_E_DOWN,
  33.     IDC_E_DELPROP,
  34.  
  35.     IDC_STATIC_KEY,
  36.     IDC_E_KEY_FIELD,
  37.     IDC_STATIC_VALUE,
  38.     IDC_E_VALUE_FIELD,
  39.  
  40.     IDC_E_COLOR,
  41.  
  42.   IDC_BTN_ASSIGNSOUND, 
  43.   IDC_BTN_ASSIGNMODEL
  44.  
  45. };
  46.  
  47. HWND hwndEnt[EntLast];
  48. CTabCtrl g_wndTabs;
  49.  
  50. int        inspector_mode;        // W_TEXTURE, W_ENTITY, or W_CONSOLE
  51.  
  52. qboolean    multiple_entities;
  53.  
  54. entity_t    *edit_entity;
  55.  
  56.  
  57. BOOL CALLBACK EntityWndProc(
  58.     HWND hwndDlg,    // handle to dialog box
  59.     UINT uMsg,        // message
  60.     WPARAM wParam,    // first message parameter
  61.     LPARAM lParam);    // second message parameter
  62.  
  63. void SizeEntityDlg(int iWidth, int iHeight);
  64. void AddProp();
  65. void GetTexMods(void);
  66.  
  67.  
  68. LRESULT (CALLBACK* OldFieldWindowProc) (HWND, UINT, WPARAM, LPARAM);
  69. LRESULT (CALLBACK* OldEntityListWindowProc) (HWND, UINT, WPARAM, LPARAM);
  70.  
  71. /*
  72. =========================
  73. FieldWndProc
  74.  
  75. Just to handle tab and enter...
  76. =========================
  77. */
  78. BOOL CALLBACK FieldWndProc(
  79.     HWND hwnd,
  80.     UINT uMsg,
  81.     WPARAM wParam,
  82.     LPARAM lParam)
  83. {
  84.     switch (uMsg)
  85.     {
  86.     case WM_CHAR:
  87.         if (LOWORD(wParam) == VK_TAB)
  88.             return FALSE;
  89.         if (LOWORD(wParam) == VK_RETURN)
  90.             return FALSE;
  91.         if (LOWORD(wParam) == VK_ESCAPE)
  92.         {
  93.             SetFocus (g_qeglobals.d_hwndCamera);
  94.             return FALSE;
  95.         }
  96.         break;
  97.  
  98.     case WM_KEYDOWN:
  99.         if (LOWORD(wParam) == VK_TAB)
  100.         {
  101.             if (hwnd == hwndEnt[EntKeyField])
  102.             {
  103.                 SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
  104.                 SetFocus (hwndEnt[EntValueField]);
  105.             }
  106.             else
  107.                 SetFocus (hwndEnt[EntKeyField]);
  108.         }
  109.         if (LOWORD(wParam) == VK_RETURN)
  110.         {
  111.             if (hwnd == hwndEnt[EntKeyField])
  112.             {
  113.                 SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
  114.                 SetFocus (hwndEnt[EntValueField]);
  115.             }
  116.             else
  117.             {
  118.                 AddProp ();
  119.                 SetFocus (g_qeglobals.d_hwndCamera);
  120.             }
  121.         }
  122.         break;
  123. //    case WM_NCHITTEST:
  124.     case WM_LBUTTONDOWN:
  125.         SetFocus (hwnd);
  126.         break;
  127.     }
  128.     return CallWindowProc (OldFieldWindowProc, hwnd, uMsg, wParam, lParam);
  129. }
  130.  
  131.  
  132. /*
  133. =========================
  134. EntityListWndProc
  135.  
  136. Just to handle enter...
  137. =========================
  138. */
  139. BOOL CALLBACK EntityListWndProc(
  140.     HWND hwnd,
  141.     UINT uMsg,
  142.     WPARAM wParam,
  143.     LPARAM lParam)
  144. {
  145.     switch (uMsg)
  146.     {
  147.     case WM_KEYDOWN:
  148.         if (LOWORD(wParam) == VK_RETURN)
  149.         {
  150.             SendMessage ( g_qeglobals.d_hwndEntity, 
  151.                           WM_COMMAND, 
  152.                           (LBN_DBLCLK<<16) + IDC_E_LIST, 
  153.                           0 );
  154.             return 0;
  155.         }
  156.         break;
  157.     }
  158.     return CallWindowProc (OldEntityListWindowProc, hwnd, uMsg, wParam, lParam);
  159. }
  160.  
  161.  
  162. /*
  163. ================
  164. GetEntityControls
  165.  
  166. Finds the controls from the dialog and
  167. moves them to the window
  168. ================
  169. */
  170. void GetEntityControls(HWND ghwndEntity)
  171. {
  172.     int i;
  173.  
  174.     for (i = 0; i < EntLast; i++)
  175.     {
  176.         if (i == EntList || i == EntProps || i == EntComment)
  177.             continue;
  178.         if (i == EntKeyField || i == EntValueField)
  179.             continue;
  180.         hwndEnt[i] = GetDlgItem(ghwndEntity, rgIds[i]);        
  181.         if (hwndEnt[i])
  182.     {
  183.             SetParent (hwndEnt[i], g_qeglobals.d_hwndEntity );
  184.             SendMessage(hwndEnt[i], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  185.     }
  186.     }
  187.  
  188.  
  189.     // SetParent apears to not modify some internal state
  190.     // on listboxes, so create it from scratch...
  191.  
  192.     hwndEnt[EntList] = CreateWindow ("listbox", NULL, 
  193.         LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT 
  194.         | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
  195.         5, 5, 180, 99,
  196.         g_qeglobals.d_hwndEntity,
  197.         (HMENU)IDC_E_LIST,
  198.         g_qeglobals.d_hInstance,
  199.         NULL);
  200.     if (!hwndEnt[EntList])
  201.         Error ("CreateWindow failed");
  202.  
  203.     hwndEnt[EntProps] = CreateWindow ("listbox", NULL, 
  204.         LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS
  205.         | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
  206.         5, 100, 180, 99,
  207.         g_qeglobals.d_hwndEntity,
  208.         (HMENU)IDC_E_PROPS,
  209.         g_qeglobals.d_hInstance,
  210.         NULL);
  211.     if (!hwndEnt[EntProps])
  212.         Error ("CreateWindow failed");
  213.  
  214.     hwndEnt[EntComment] = CreateWindow ("edit", NULL, 
  215.         ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
  216.         5, 100, 180, 99,
  217.         g_qeglobals.d_hwndEntity,
  218.         (HMENU)IDC_E_COMMENT,
  219.         g_qeglobals.d_hInstance,
  220.         NULL);
  221.     if (!hwndEnt[EntComment])
  222.         Error ("CreateWindow failed");
  223.  
  224.     hwndEnt[EntKeyField] = CreateWindow ("edit", NULL, 
  225.         WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
  226.         5, 100, 180, 99,
  227.         g_qeglobals.d_hwndEntity,
  228.         (HMENU)IDC_E_KEY_FIELD,
  229.         g_qeglobals.d_hInstance,
  230.         NULL);
  231.     if (!hwndEnt[EntKeyField])
  232.         Error ("CreateWindow failed");
  233.  
  234.     hwndEnt[EntValueField] = CreateWindow ("edit", NULL, 
  235.         WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
  236.         5, 100, 180, 99,
  237.         g_qeglobals.d_hwndEntity,
  238.         (HMENU)IDC_E_VALUE_FIELD,
  239.         g_qeglobals.d_hInstance,
  240.         NULL);
  241.     if (!hwndEnt[EntValueField])
  242.         Error ("CreateWindow failed");
  243.  
  244.   g_wndTabs.SubclassDlgItem(IDC_TAB_MODE, CWnd::FromHandle(ghwndEntity));
  245.   hwndEnt[EntTab] = g_wndTabs.GetSafeHwnd();
  246.   g_wndTabs.InsertItem(0, "Groups");
  247.   ::SetParent(g_wndTabs.GetSafeHwnd(), g_qeglobals.d_hwndEntity);
  248.  
  249.   if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  250.   {
  251.       g_qeglobals.d_hwndEdit = CreateWindow ("edit", NULL, ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
  252.                                                5, 100, 180, 99, g_qeglobals.d_hwndEntity, (HMENU)IDC_E_STATUS,
  253.                                                g_qeglobals.d_hInstance, NULL);
  254.       if (!g_qeglobals.d_hwndEdit)
  255.           Error ("CreateWindow failed");
  256.     g_wndTabs.InsertItem(0, "Console");
  257.     g_wndTabs.InsertItem(0, "Textures");
  258.   }
  259.   g_wndTabs.InsertItem(0, "Entities");
  260.   g_wndTabs.ShowWindow(SW_SHOW);
  261.  
  262. #if 0
  263.     for (i=0 ; i<12 ; i++)
  264.     {
  265.         hwndEnt[EntCheck1 + i] = CreateWindow ("button", NULL, 
  266.         BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
  267.         5, 100, 180, 99,
  268.         entwindow,
  269.         (HMENU)IDC_E_STATUS,
  270.         main_instance,
  271.         NULL);
  272.         if (!hwndEnt[EntCheck1 + i])
  273.             Error ("CreateWindow failed");
  274.     }
  275. #endif
  276.     SendMessage(hwndEnt[EntList], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  277.     SendMessage(hwndEnt[EntProps], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  278.     SendMessage(hwndEnt[EntComment], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  279.     SendMessage(hwndEnt[EntKeyField], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  280.     SendMessage(hwndEnt[EntValueField], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  281.     SendMessage(hwndEnt[EntTab], WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  282.  
  283.     if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  284.         SendMessage(g_qeglobals.d_hwndEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), (LPARAM)TRUE);
  285. }
  286.  
  287.  
  288.  
  289. /*
  290. ===============================================================
  291.  
  292. ENTITY WINDOW
  293.  
  294. ===============================================================
  295. */
  296.  
  297.  
  298. void FillClassList (void)
  299. {
  300.     eclass_t    *pec;
  301.     int            iIndex;
  302.  
  303.     SendMessage(hwndEnt[EntList], LB_RESETCONTENT, 0 , 0);
  304.  
  305.     for (pec = eclass ; pec ; pec = pec->next)
  306.     {
  307.         iIndex = SendMessage(hwndEnt[EntList], LB_ADDSTRING, 0 , (LPARAM)pec->name);
  308.         SendMessage(hwndEnt[EntList], LB_SETITEMDATA, iIndex, (LPARAM)pec);
  309.     }    
  310.  
  311. }
  312.  
  313.  
  314. /*
  315. ==============
  316. WEnt_Create
  317. ==============
  318. */
  319. void WEnt_Create (HINSTANCE hInstance)
  320. {
  321.     WNDCLASS   wc;
  322.  
  323.     /* Register the camera class */
  324.     memset (&wc, 0, sizeof(wc));
  325.  
  326.     wc.style         = CS_NOCLOSE | CS_OWNDC;
  327.     wc.lpfnWndProc   = (WNDPROC)EntityWndProc;
  328.     wc.cbClsExtra    = 0;
  329.     wc.cbWndExtra    = 0;
  330.     wc.hInstance     = hInstance;
  331.     wc.hIcon         = 0;
  332.     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
  333.     wc.hbrBackground = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
  334.     wc.lpszMenuName  = NULL;
  335.     wc.lpszClassName = ENT_WINDOW_CLASS;
  336.  
  337.     RegisterClass (&wc);
  338.  
  339.     int nStyle = (g_pParentWnd->CurrentStyle() == QR_QE4) ? QE3_STYLE : QE3_STYLE2;
  340.       g_qeglobals.d_hwndEntity = CreateWindow (ENT_WINDOW_CLASS ,
  341.         "Entity",
  342.         nStyle,
  343.         20,
  344.         20,
  345.         100,
  346.         480,    // size
  347.  
  348.         g_qeglobals.d_hwndMain,    // parent
  349.         0,        // no menu
  350.         hInstance,
  351.         NULL);
  352.  
  353.     if (!g_qeglobals.d_hwndEntity )
  354.         Error ("Couldn't create Entity window");
  355. }
  356.  
  357. /*
  358. ==============
  359. CreateEntityWindow
  360. ==============
  361. */
  362. BOOL CreateEntityWindow(HINSTANCE hInstance)
  363. {
  364.     HWND hwndEntityPalette;
  365.  
  366.     inspector_mode = W_ENTITY;
  367.  
  368.     WEnt_Create (hInstance);
  369.  
  370.     hwndEntityPalette = CreateDialog(hInstance, (char *)IDD_ENTITY, g_qeglobals.d_hwndMain, (DLGPROC)NULL);
  371.     if (!hwndEntityPalette)
  372.         Error ("CreateDialog failed");
  373.  
  374.     GetEntityControls (hwndEntityPalette);
  375.     DestroyWindow (hwndEntityPalette);
  376.  
  377.     OldFieldWindowProc = (WNDPROC)GetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC);
  378.     SetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC, (long)FieldWndProc);
  379.     SetWindowLong (hwndEnt[EntValueField], GWL_WNDPROC, (long)FieldWndProc);
  380.  
  381.     OldEntityListWindowProc = (WNDPROC)GetWindowLong (hwndEnt[EntList], GWL_WNDPROC);
  382.     SetWindowLong (hwndEnt[EntList], GWL_WNDPROC, (long)EntityListWndProc);
  383.  
  384.     FillClassList ();
  385.  
  386.  
  387.     LoadWindowPlacement(g_qeglobals.d_hwndEntity, "EntityWindowPlace");
  388.     ShowWindow (g_qeglobals.d_hwndEntity, SW_HIDE);
  389.     SetInspectorMode (W_CONSOLE);
  390.  
  391.     return TRUE;
  392. }
  393.  
  394. /*
  395. ==============
  396. SetInspectorMode
  397. ==============
  398. */
  399. void SetInspectorMode(int iType)
  400. {
  401.     RECT rc;
  402.     HMENU hMenu = GetMenu( g_qeglobals.d_hwndMain );
  403.  
  404.   if ((g_pParentWnd->CurrentStyle() == QR_SPLIT || g_pParentWnd->CurrentStyle() == QR_SPLITZ) && (iType == W_TEXTURE || iType == W_CONSOLE))
  405.     return;
  406.  
  407.  
  408.     // Is the caller asking us to cycle to the next window?
  409.  
  410.     if (iType == -1)
  411.     {
  412.         if (inspector_mode == W_ENTITY)
  413.             iType = W_TEXTURE;
  414.         else if (inspector_mode == W_TEXTURE)
  415.             iType = W_CONSOLE;
  416.         else if (inspector_mode == W_CONSOLE)
  417.       iType = W_GROUP;
  418.     else
  419.             iType = W_ENTITY;
  420.     }        
  421.  
  422.     inspector_mode = iType;
  423.     switch(iType)
  424.     {
  425.         
  426.     case W_ENTITY:
  427.         SetWindowText(g_qeglobals.d_hwndEntity, "Entity");
  428.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_ENABLED | MF_BYCOMMAND );
  429.     // entity is always first in the inspector
  430.     g_wndTabs.SetCurSel(0);
  431.         break;
  432.  
  433.     case W_TEXTURE:
  434.     SetWindowText(g_qeglobals.d_hwndEntity, "Textures");
  435.     g_pParentWnd->GetTexWnd()->FocusEdit();
  436.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
  437.     if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  438.       g_wndTabs.SetCurSel(1);
  439.         break;
  440.  
  441.     case W_CONSOLE:
  442.         SetWindowText(g_qeglobals.d_hwndEntity, "Console");        
  443.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
  444.     if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  445.       g_wndTabs.SetCurSel(2);
  446.         break;
  447.  
  448.   case W_GROUP:
  449.         SetWindowText(g_qeglobals.d_hwndEntity, "Groups");        
  450.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
  451.     if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  452.       g_wndTabs.SetCurSel(3);
  453.     else
  454.       g_wndTabs.SetCurSel(1);
  455.         break;
  456.  
  457.  
  458.     default:
  459.         break;
  460.     }
  461.  
  462.     GetWindowRect (g_qeglobals.d_hwndEntity, &rc);
  463.     SizeEntityDlg( rc.right - rc.left - 8, rc.bottom - rc.top - 20);
  464.  
  465.  
  466. //    InvalidateRect(entwindow, NULL, true);
  467. //    ShowWindow (entwindow, SW_SHOW);
  468. //    UpdateWindow (entwindow);
  469.  
  470.   HWND hFlag = (g_pParentWnd->CurrentStyle() == QR_QE4) ? HWND_TOP : HWND_TOPMOST;
  471.     SetWindowPos( g_qeglobals.d_hwndEntity, hFlag, rc.left, rc.top,  rc.right - rc.left, rc.bottom - rc.top, SWP_NOSIZE | SWP_NOMOVE );
  472.     RedrawWindow (g_qeglobals.d_hwndEntity, NULL, NULL, RDW_ERASE | RDW_INVALIDATE| RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
  473. }
  474.  
  475.  
  476.  
  477.  
  478.  
  479. // SetKeyValuePairs
  480. //
  481. // Reset the key/value (aka property) listbox and fill it with the 
  482. // k/v pairs from the entity being edited.
  483. //
  484.  
  485. void SetKeyValuePairs (bool bClearMD3)
  486. {
  487.     epair_t    *pep;
  488.     RECT    rc;
  489.     char    sz[4096];
  490.     
  491.     if (edit_entity == NULL)
  492.         return;
  493.     
  494.     // set key/value pair list
  495.     
  496.     GetWindowRect(hwndEnt[EntProps], &rc);
  497.     SendMessage(hwndEnt[EntProps], LB_SETCOLUMNWIDTH, (rc.right - rc.left)/2, 0);
  498.     SendMessage(hwndEnt[EntProps], LB_RESETCONTENT, 0, 0);
  499.     
  500.     // Walk through list and add pairs
  501.     
  502.     for (pep = edit_entity->epairs ; pep ; pep = pep->next)
  503.     {
  504.         // if the key is less than 8 chars, add a tab for alignment
  505.         if (strlen(pep->key) > 8)
  506.             sprintf (sz, "%s\t%s", pep->key, pep->value);
  507.         else
  508.             sprintf (sz, "%s\t\t%s", pep->key, pep->value);
  509.         SendMessage(hwndEnt[EntProps], LB_ADDSTRING, 0, (LPARAM)sz);
  510.     }
  511.     
  512.     if (edit_entity->eclass->nShowFlags & ECLASS_MISCMODEL)
  513.     {
  514.         // if this is a misc_model
  515.         // cache the md3 for display later
  516.         if (bClearMD3)
  517.         {
  518.             edit_entity->md3Class = NULL;
  519.         }
  520.         //char *pModel = ValueForKey(edit_entity, "model");
  521.         
  522.         /*
  523.         if (pModel != NULL)
  524.         {
  525.         GetCachedModel(pModel, vMin, vMax);
  526.         }
  527.         */
  528.     }
  529.         
  530.     Sys_UpdateWindows(W_CAMERA | W_XY);
  531.     
  532. }
  533.  
  534. // SetSpawnFlags
  535. // 
  536. // Update the checkboxes to reflect the flag state of the entity
  537. //
  538. void SetSpawnFlags(void)
  539. {
  540.     int        f;
  541.     int        i;
  542.     int        v;
  543.  
  544.     f = atoi(ValueForKey (edit_entity, "spawnflags"));
  545.     for (i=0 ; i<12 ; i++)
  546.     {
  547.         v = !!(f&(1<<i));
  548.         SendMessage(hwndEnt[EntCheck1+i], BM_SETCHECK, v, 0);
  549.     }
  550. }
  551.  
  552.  
  553. // GetSpawnFlags
  554. // 
  555. // Update the entity flags to reflect the state of the checkboxes
  556. //
  557. void GetSpawnFlags(void)
  558. {
  559.     int        f;
  560.     int        i, v;
  561.     char    sz[32];
  562.  
  563.     f = 0;
  564.     for (i=0 ; i<12 ; i++)
  565.     {
  566.         v = SendMessage(hwndEnt[EntCheck1+i], BM_GETCHECK, 0, 0);
  567.         f |= v<<i;
  568.     }
  569.  
  570.     sprintf (sz, "%i", f);
  571.  
  572.     if (multiple_entities)
  573.     {
  574.         brush_t    *b;
  575.  
  576.         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  577.             SetKeyValue(b->owner, "spawnflags", sz);
  578.     }
  579.     else
  580.         SetKeyValue (edit_entity, "spawnflags", sz);
  581.     SetKeyValuePairs ();
  582. }
  583.  
  584. // UpdateSel
  585. //
  586. // Update the listbox, checkboxes and k/v pairs to reflect the new selection
  587. //
  588. BOOL UpdateSel(int iIndex, eclass_t *pec)
  589. {
  590.     int        i;
  591.     brush_t    *b;
  592.  
  593.     if (selected_brushes.next == &selected_brushes)
  594.     {
  595.         edit_entity = world_entity;
  596.         multiple_entities = false;
  597.     }
  598.     else
  599.     {
  600.         edit_entity = selected_brushes.next->owner;
  601.         for (b=selected_brushes.next->next ; b != &selected_brushes ; b=b->next)
  602.         {
  603.             if (b->owner != edit_entity)
  604.             {
  605.                 multiple_entities = true;
  606.                 break;
  607.             }
  608.         }
  609.     }
  610.  
  611.     if (iIndex != LB_ERR)
  612.         SendMessage(hwndEnt[EntList], LB_SETCURSEL, iIndex, 0);
  613.  
  614.     if (pec == NULL)
  615.         return TRUE;
  616.  
  617.     // Set up the description
  618.  
  619.     SendMessage(hwndEnt[EntComment], WM_SETTEXT, 0, 
  620.             (LPARAM)TranslateString(pec->comments));
  621.  
  622.     for (i=0 ; i<8 ; i++)
  623.     {
  624.         HWND hwnd = hwndEnt[EntCheck1+i];
  625.         if (pec->flagnames[i] && pec->flagnames[i][0] != 0)
  626.         {
  627.             EnableWindow(hwnd, TRUE);
  628.             SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)pec->flagnames[i]);
  629.         } else {
  630.  
  631.             // disable check box
  632.             SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)" ");
  633.             EnableWindow(hwnd, FALSE);
  634.         }
  635.     }
  636.  
  637.     SetSpawnFlags();
  638.     SetKeyValuePairs();
  639.     return TRUE;
  640. }
  641.  
  642. BOOL UpdateEntitySel(eclass_t *pec)
  643. {
  644.     int iIndex;
  645.  
  646.     iIndex = (int)SendMessage(hwndEnt[EntList], LB_FINDSTRINGEXACT, 
  647.             (WPARAM)-1, (LPARAM)pec->name);
  648.  
  649.     return UpdateSel(iIndex, pec);
  650. }
  651.  
  652. // CreateEntity
  653. //
  654. // Creates a new entity based on the currently selected brush and entity type.
  655. //
  656.  
  657. void CreateEntity(void)
  658. {
  659.     eclass_t *pecNew;
  660.     entity_t *petNew;
  661.     int i;
  662.     HWND hwnd;
  663.     char sz[1024];
  664.  
  665.     // check to make sure we have a brush
  666.  
  667.     if (selected_brushes.next == &selected_brushes)
  668.     {
  669.         MessageBox(g_qeglobals.d_hwndMain, "You must have a selected brush to create an entity"
  670.             , "info", 0);
  671.         return;
  672.     }
  673.  
  674.  
  675.     // find out what type of entity we are trying to create
  676.  
  677.     hwnd = hwndEnt[EntList];
  678.  
  679.     i = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);
  680.  
  681.     if (i < 0)
  682.     {
  683.         MessageBox(g_qeglobals.d_hwndMain, "You must have a selected class to create an entity"
  684.             , "info", 0);
  685.         return;
  686.     }
  687.  
  688.     SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);
  689.  
  690.     if (!stricmp(sz, "worldspawn"))
  691.     {
  692.         MessageBox(g_qeglobals.d_hwndMain, "Can't create an entity with worldspawn.", "info", 0);
  693.         return;
  694.     }
  695.  
  696.     pecNew = Eclass_ForName(sz, false);
  697.  
  698.     // create it
  699.  
  700.     petNew = Entity_Create(pecNew);
  701.  
  702.     if (petNew == NULL)
  703.     {
  704.         MessageBox(g_qeglobals.d_hwndMain, "Failed to create entity.", "info", 0);
  705.         return;
  706.     }
  707.  
  708.     if (selected_brushes.next == &selected_brushes)
  709.         edit_entity = world_entity;
  710.     else
  711.         edit_entity = selected_brushes.next->owner;
  712.  
  713.     SetKeyValuePairs();
  714.     Select_Deselect ();
  715.     Select_Brush (edit_entity->brushes.onext);
  716.   Sys_UpdateWindows(W_ALL);
  717.  
  718. }
  719.  
  720.  
  721.  
  722. /*
  723. ===============
  724. AddProp
  725.  
  726. ===============
  727. */
  728. void AddProp()
  729. {
  730.     char    key[4096];
  731.     char    value[4096];
  732.  
  733.     if (edit_entity == NULL)
  734.         return;
  735.  
  736.     // Get current selection text
  737.  
  738.     SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(key)-1, (LPARAM)key);    
  739.     SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(value)-1, (LPARAM)value);    
  740.  
  741.     if (multiple_entities)
  742.     {
  743.         brush_t    *b;
  744.  
  745.         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  746.             SetKeyValue(b->owner, key, value);
  747.     }
  748.     else
  749.         SetKeyValue(edit_entity, key, value);
  750.  
  751.     // refresh the prop listbox
  752.     SetKeyValuePairs();    
  753.  
  754.     // if it's a plugin entity, perhaps we need to update some drawing parameters
  755.     // NOTE: perhaps moving this code to a seperate func would help if we need it in other places
  756.     // TODO: we need to call some update func in the IPluginEntity in case model name changes etc.
  757.     // ( for the moment only bounding brush is updated ), see UpdateModelBrush in Ritual's Q3Radiant
  758.     if (edit_entity->eclass->nShowFlags & ECLASS_PLUGINENTITY)
  759.     {
  760.         vec3_t    mins, maxs;
  761.         edit_entity->pPlugEnt->GetBounds( mins, maxs );
  762.         // replace old bounding brush by newly computed one
  763.         // NOTE: this part is similar to Entity_BuildModelBrush in Ritual's Q3Radiant, it can be
  764.         // usefull moved into a seperate func
  765.         brush_t *b,*oldbrush;
  766.         if (edit_entity->brushes.onext != &edit_entity->brushes)
  767.             oldbrush = edit_entity->brushes.onext;
  768.         b = Brush_Create (mins, maxs, &edit_entity->eclass->texdef);
  769.         Entity_LinkBrush (edit_entity, b);
  770.         Brush_Build( b, true );
  771.         Select_Deselect();
  772.         Brush_AddToList (edit_entity->brushes.onext, &selected_brushes);
  773.         if (oldbrush)
  774.             Brush_Free( oldbrush );
  775.     }
  776.  
  777. }
  778.  
  779. /*
  780. ===============
  781. DelProp
  782.  
  783. ===============
  784. */
  785. void DelProp(void)
  786. {
  787.     char    sz[4096];
  788.  
  789.     if (edit_entity == NULL)
  790.         return;
  791.  
  792.     // Get current selection text
  793.  
  794.     SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz)-1, (LPARAM)sz);    
  795.  
  796.     if (multiple_entities)
  797.     {
  798.         brush_t    *b;
  799.  
  800.         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  801.             DeleteKey(b->owner, sz);
  802.     }
  803.     else
  804.         DeleteKey(edit_entity, sz);
  805.  
  806.     // refresh the prop listbox
  807.  
  808.     SetKeyValuePairs();    
  809. }
  810.  
  811. BOOL GetSelectAllCriteria(CString &strKey, CString &strVal) {
  812.     char    sz[4096];
  813.     HWND hwnd = hwndEnt[EntProps];
  814.     int i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);    
  815.   if (i >= 0 && inspector_mode == W_ENTITY) {
  816.       SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz), (LPARAM)sz);    
  817.     strKey = sz;
  818.       SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(sz), (LPARAM)sz);    
  819.     strVal = sz;
  820.     return TRUE;
  821.   }
  822.   return FALSE;
  823. }
  824.  
  825. /*
  826. ===============
  827. EditProp
  828.  
  829. ===============
  830. */
  831. void EditProp(void)
  832. {
  833.     int i;
  834.     HWND hwnd;
  835.     char    sz[4096];
  836.     char    *val;
  837.  
  838.     if (edit_entity == NULL)
  839.         return;
  840.  
  841.     hwnd = hwndEnt[EntProps];
  842.  
  843.     // Get current selection text
  844.  
  845.     i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);    
  846.  
  847.     if (i < 0)
  848.         return;
  849.  
  850.     SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);    
  851.  
  852.     // strip it down to the key name
  853.  
  854.     for(i=0;sz[i] != '\t';i++)
  855.     ;
  856.  
  857.     sz[i] = '\0';
  858.  
  859.     val = sz + i + 1;
  860.     if (*val == '\t')
  861.         val++;
  862.  
  863.     SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)sz);    
  864.     SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)val);    
  865. }
  866.  
  867.  
  868. HDWP    defer;
  869. int        col;
  870. void MOVE(HWND e, int x, int y, int w, int h, HWND hwndPlacement = HWND_TOP, int swp = SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOZORDER)
  871. {
  872. //    defer=DeferWindowPos(defer,e,HWND_TOP,col+(x),y,w,h,SWP_SHOWWINDOW);
  873. //    MoveWindow (e, col+x, y, w, h, FALSE);
  874.     SetWindowPos (e, hwndPlacement, col+x, y, w, h, swp);
  875. }
  876.  
  877.  
  878. /*
  879. ===============
  880. SizeEnitityDlg
  881.  
  882. Positions all controls so that the active inspector
  883. is displayed correctly and the inactive ones are
  884. off the side
  885. ===============
  886. */
  887. void SizeEntityDlg(int iWidth, int iHeight)
  888. {
  889.     int y, x, xCheck, yCheck;
  890.     int i, iRow;
  891.     int    w, h;
  892.  
  893.     if (iWidth < 32 || iHeight < 32)
  894.         return;
  895.  
  896.     SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 0, 0);
  897.   iHeight -= 24;
  898.  
  899.  
  900.     //==========================================
  901.  
  902.  
  903.   //
  904.     // console
  905.     //
  906.   if (inspector_mode == W_CONSOLE)
  907.   {
  908.     col = 0;
  909.   }
  910.   else
  911.   {
  912.     col = iWidth;
  913.   }
  914.  
  915.   if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  916.       MOVE(g_qeglobals.d_hwndEdit,    DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
  917.  
  918.     //==========================================
  919.  
  920.     //
  921.     // texture controls
  922.     //
  923.   if (inspector_mode == W_TEXTURE)
  924.   {
  925.     col = 0;
  926.   }
  927.   else
  928.   {
  929.     col = iWidth;
  930.   }
  931.  
  932.   if (g_pParentWnd->CurrentStyle() > 0 && g_pParentWnd->CurrentStyle() < 3)
  933.       MOVE(g_qeglobals.d_hwndTexture,    DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
  934.  
  935.   if (inspector_mode == W_GROUP)
  936.   {
  937.     col = 0;
  938.   }
  939.   else
  940.   {
  941.     col = iWidth;
  942.   }
  943.  
  944.   MOVE(g_qeglobals.d_hwndGroup,    DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
  945.  
  946.     //==========================================
  947.  
  948.     //
  949.     // entity controls
  950.     //
  951.   if (inspector_mode == W_ENTITY)
  952.   {
  953.     col = 0;
  954.   }
  955.   else
  956.   {
  957.     col = iWidth;
  958.   }
  959.  
  960.  
  961.  
  962.     // top half includes the entity list (2/3) and the 
  963.     // comments (1/3) - 2 gaps, above and below.
  964.  
  965.     y = iHeight/2;
  966.     y -= 2 * DlgYBorder;
  967.     y = y / 3;
  968.     w = iWidth - (2 * DlgXBorder);
  969.     MOVE(hwndEnt[EntList], DlgXBorder, DlgYBorder, w, 2 * y);
  970.     
  971.     MOVE(hwndEnt[EntComment], DlgXBorder, 2 * DlgYBorder + 2 * y, w, y - (2 * DlgYBorder));
  972.  
  973.     // bottom half includes flags (fixed), k/v pairs,
  974.     // and buttons (fixed).
  975.  
  976.     // xCheck = width of a single check box
  977.     // yCheck = distance from top of one check to the next
  978.  
  979.     xCheck = (iWidth - (2 * DlgXBorder)) / 3;
  980.     yCheck = 18;
  981.  
  982.     x = DlgXBorder;
  983.  
  984.     for (iRow = 0; iRow <= 12; iRow += 4)
  985.     {
  986.         y = iHeight/2;
  987.     
  988.         for (i = 0; i < 4; i++)
  989.         {
  990.             MOVE(hwndEnt[EntCheck1 + i + iRow],
  991.                 x, y, xCheck, yCheck);
  992.             y += yCheck;
  993.         }
  994.  
  995.         x += xCheck;
  996.     }
  997.  
  998.     //
  999.     // properties scroll box
  1000.     //
  1001.     y = iHeight/2 + 4 * yCheck;
  1002.  
  1003.     w = iWidth - (2 * DlgXBorder);
  1004.     h = (iHeight - (yCheck * 5 + 2 * DlgYBorder) ) - y;
  1005.  
  1006.     MOVE(hwndEnt[EntProps], DlgXBorder, y, w, h);
  1007.  
  1008.     y += h + DlgYBorder;
  1009.     
  1010.     //
  1011.     // key / value fields
  1012.     //
  1013.     w = iWidth-(DlgXBorder+45);
  1014.     MOVE(hwndEnt[EntKeyLabel], DlgXBorder, y, 40, yCheck);
  1015.     MOVE(hwndEnt[EntKeyField], DlgXBorder+40, y, w, yCheck);
  1016.     y += yCheck;        
  1017.  
  1018.     MOVE(hwndEnt[EntValueLabel], DlgXBorder, y, 40, yCheck);
  1019.     MOVE(hwndEnt[EntValueField], DlgXBorder+40, y, w, yCheck);
  1020.     y += yCheck;        
  1021.  
  1022.     //
  1023.     // angle check boxes
  1024.     //
  1025.   y += 2;
  1026.     i = y;
  1027.     x = DlgXBorder;
  1028.  
  1029.     xCheck = yCheck*2;
  1030.  
  1031.     MOVE(hwndEnt[EntDir135], x, y, xCheck, yCheck);
  1032.     y += yCheck;        
  1033.     
  1034.     MOVE(hwndEnt[EntDir180], x, y, xCheck, yCheck);
  1035.     y += yCheck;        
  1036.     
  1037.     MOVE(hwndEnt[EntDir225], x, y, xCheck, yCheck);
  1038.  
  1039.     y = i;
  1040.     x += xCheck;
  1041.  
  1042.     
  1043.     MOVE(hwndEnt[EntDir90], x, y, xCheck, yCheck);
  1044.     y += yCheck;        
  1045.     y += yCheck;        
  1046.     
  1047.     MOVE(hwndEnt[EntDir270], x, y, xCheck, yCheck);
  1048.  
  1049.     y = i;
  1050.     x += xCheck;
  1051.  
  1052.     
  1053.     MOVE(hwndEnt[EntDir45], x, y, xCheck, yCheck);
  1054.     y += yCheck;        
  1055.     
  1056.     MOVE(hwndEnt[EntDir0], x, y, xCheck, yCheck);
  1057.     y += yCheck;        
  1058.     
  1059.     MOVE(hwndEnt[EntDir315], x, y, xCheck, yCheck);
  1060.  
  1061.     y = i + yCheck/2;
  1062.     x += xCheck + xCheck/2;
  1063.  
  1064.     
  1065.     MOVE(hwndEnt[EntDirUp], x, y, xCheck, yCheck);
  1066.     y += yCheck;        
  1067.     
  1068.     MOVE(hwndEnt[EntDirDown], x, y, xCheck, yCheck);
  1069.  
  1070.     y = i;
  1071.     x += 1.5 * xCheck;
  1072.     
  1073.     MOVE(hwndEnt[EntDelProp], x, y, xCheck*2, yCheck);
  1074.     y += yCheck + 4;        
  1075.  
  1076.   MOVE(hwndEnt[EntAssignSounds], x, y, xCheck*2, yCheck);
  1077.     y += yCheck;        
  1078.   MOVE(hwndEnt[EntAssignModels], x, y, xCheck*2, yCheck);
  1079.  
  1080.   // tab selector is always visible
  1081.   col = 0;
  1082.   iHeight += 24;
  1083.   MOVE(hwndEnt[EntTab], 0,0,iWidth,iHeight, HWND_BOTTOM, SWP_NOACTIVATE | SWP_NOCOPYBITS);
  1084.  
  1085.     SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 1, 0);
  1086. //    InvalidateRect(entwindow, NULL, TRUE);
  1087. }
  1088.  
  1089. void AssignSound()
  1090. {
  1091.   CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
  1092.   AddSlash(strBasePath);
  1093.   CString strPath = strBasePath;
  1094.   strPath += "sound\\";
  1095.  
  1096.   CWaveOpen dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Sound files (*.wav)|*.wav||", g_pParentWnd);
  1097.   dlgFile.m_ofn.lpstrInitialDir = strPath;
  1098.   if (dlgFile.DoModal() == IDOK)
  1099.   {
  1100.       SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"noise");    
  1101.     CString str = dlgFile.GetPathName().GetBuffer(0);
  1102.     str.MakeLower();
  1103.     strBasePath.MakeLower();
  1104.     QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0));
  1105.     QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0));
  1106.     int n = str.Find(strBasePath);
  1107.     if (n == 0)
  1108.     {
  1109.       str = str.Right(str.GetLength() - strBasePath.GetLength());
  1110.     }
  1111.  
  1112.       SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0));    
  1113.     AddProp();
  1114.     g_pParentWnd->GetXYWnd()->SetFocus();
  1115.   }
  1116. }
  1117.  
  1118. void AssignModel()
  1119. {
  1120.   CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
  1121.   AddSlash(strBasePath);
  1122.   CString strPath = strBasePath;
  1123.   strPath += "models\\mapobjects\\";
  1124.  
  1125.   CFileDialog dlgFile(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, "Model files (*.md3)|*.md3||", g_pParentWnd);
  1126.   dlgFile.m_ofn.lpstrInitialDir = strPath;
  1127.   if (dlgFile.DoModal() == IDOK)
  1128.   {
  1129.       SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"model");
  1130.     CString str = dlgFile.GetPathName().GetBuffer(0);
  1131.     str.MakeLower();
  1132.     strBasePath.MakeLower();
  1133.     QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0));
  1134.     QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0));
  1135.     int n = str.Find(strBasePath);
  1136.     if (n == 0)
  1137.     {
  1138.       str = str.Right(str.GetLength() - strBasePath.GetLength());
  1139.     }
  1140.  
  1141.       SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0));    
  1142.     AddProp();
  1143.     edit_entity->md3Class = NULL;
  1144.     edit_entity->brushes.onext->bModelFailed = false;
  1145.     g_pParentWnd->GetXYWnd()->SetFocus();
  1146.   }
  1147. }
  1148.  
  1149.  
  1150. /*
  1151. =========================
  1152. EntityWndProc
  1153. =========================
  1154. */
  1155. BOOL CALLBACK EntityWndProc(
  1156.     HWND hwndDlg,    // handle to dialog box
  1157.     UINT uMsg,        // message
  1158.     WPARAM wParam,    // first message parameter
  1159.     LPARAM lParam)    // second message parameter
  1160. {
  1161.   LPNMHDR lpnmh = NULL;
  1162.     RECT    rc;
  1163.  
  1164.     GetClientRect(hwndDlg, &rc);
  1165.  
  1166.     switch (uMsg)
  1167.     {
  1168.  
  1169.       case WM_CHAR :
  1170.       {
  1171.         char c = toupper(LOWORD(wParam));
  1172.         // escape: hide the window
  1173.             if (c == 27)
  1174.                 ShowWindow(hwndDlg, SW_HIDE);
  1175.         if (c == 'N')
  1176.           g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_ENTITY, 0);
  1177.         else
  1178.         if (c == 'O')
  1179.           g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_CONSOLE, 0);
  1180.         else
  1181.         if (c == 'T')
  1182.           g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_TEXTURE, 0);
  1183.         else
  1184.         if (c == 'G')
  1185.           g_pParentWnd->PostMessage(WM_COMMAND, ID_VIEW_GROUPS, 0);
  1186.         else
  1187.                 DefWindowProc (hwndDlg, uMsg, wParam, lParam);
  1188.         break;
  1189.       }
  1190.  
  1191.       case WM_NOTIFY:
  1192.         lpnmh = reinterpret_cast<LPNMHDR>(lParam);
  1193.         if (lpnmh->hwndFrom == g_wndTabs.GetSafeHwnd()) {
  1194.           if ( lpnmh->code == TCN_SELCHANGE)
  1195.           {
  1196.             int n = g_wndTabs.GetCurSel();
  1197.             if (g_pParentWnd->CurrentStyle() == 2 || g_pParentWnd->CurrentStyle() == 1)
  1198.             {
  1199.               if (n == 0) {
  1200.                 SetInspectorMode(W_ENTITY);
  1201.               } else if (n == 1) {
  1202.                 SetInspectorMode(W_TEXTURE);
  1203.               } else if (n == 2) {
  1204.                 SetInspectorMode(W_CONSOLE);
  1205.               } else {
  1206.                 SetInspectorMode(W_GROUP);
  1207.               }
  1208.             }
  1209.             else
  1210.             {
  1211.               if (n == 0) {
  1212.                 SetInspectorMode(W_ENTITY);
  1213.               } else if (n == 1) {
  1214.                 SetInspectorMode(W_GROUP);
  1215.               }
  1216.             }
  1217.           }
  1218.         }
  1219.         break;
  1220.         
  1221.     case WM_SIZE:
  1222.  
  1223.             DefWindowProc (hwndDlg, uMsg, wParam, lParam);
  1224.       break;
  1225.  
  1226.   case WM_DESTROY:
  1227.       SaveWindowPlacement(g_qeglobals.d_hwndEntity, "EntityWindowPlace");
  1228.       DefWindowProc(hwndDlg, uMsg, wParam, lParam);
  1229.       break;
  1230.  
  1231.     case WM_GETMINMAXINFO:
  1232.         {
  1233.             LPMINMAXINFO    lpmmi;
  1234.  
  1235.             lpmmi = (LPMINMAXINFO) lParam;
  1236.             lpmmi->ptMinTrackSize.x = 320;
  1237.             lpmmi->ptMinTrackSize.y = 500;
  1238.         }
  1239.         return 0;
  1240.  
  1241.     case WM_WINDOWPOSCHANGING:
  1242.         {
  1243.             LPWINDOWPOS    lpwp;
  1244.             lpwp = (LPWINDOWPOS) lParam;
  1245.  
  1246.             DefWindowProc (hwndDlg, uMsg, wParam, lParam);
  1247.  
  1248.             lpwp->flags |= SWP_NOCOPYBITS;
  1249.             SizeEntityDlg(lpwp->cx-8, lpwp->cy-32);
  1250.             return 0;
  1251.  
  1252.         }
  1253.         return 0;
  1254.  
  1255.  
  1256.     case WM_COMMAND: 
  1257.         switch (LOWORD(wParam)) { 
  1258.  
  1259.     case IDC_BTN_ASSIGNSOUND:
  1260.       AssignSound();
  1261.       break;
  1262.  
  1263.     case IDC_BTN_ASSIGNMODEL:
  1264.       AssignModel();
  1265.       break;
  1266.  
  1267.         case IDC_E_DELPROP:
  1268.             DelProp();
  1269.             SetFocus (g_qeglobals.d_hwndCamera);
  1270.             break;
  1271.  
  1272.         case IDC_E_0:
  1273.             SetKeyValue (edit_entity, "angle", "360");
  1274.             SetFocus (g_qeglobals.d_hwndCamera);
  1275.             SetKeyValuePairs ();
  1276.             break;
  1277.         case IDC_E_45:
  1278.             SetKeyValue (edit_entity, "angle", "45");
  1279.             SetFocus (g_qeglobals.d_hwndCamera);
  1280.             SetKeyValuePairs ();
  1281.             break;
  1282.         case IDC_E_90:
  1283.             SetKeyValue (edit_entity, "angle", "90");
  1284.             SetFocus (g_qeglobals.d_hwndCamera);
  1285.             SetKeyValuePairs ();
  1286.             break;
  1287.         case IDC_E_135:
  1288.             SetKeyValue (edit_entity, "angle", "135");
  1289.             SetFocus (g_qeglobals.d_hwndCamera);
  1290.             SetKeyValuePairs ();
  1291.             break;
  1292.         case IDC_E_180:
  1293.             SetKeyValue (edit_entity, "angle", "180");
  1294.             SetFocus (g_qeglobals.d_hwndCamera);
  1295.             SetKeyValuePairs ();
  1296.             break;
  1297.         case IDC_E_225:
  1298.             SetKeyValue (edit_entity, "angle", "225");
  1299.             SetFocus (g_qeglobals.d_hwndCamera);
  1300.             SetKeyValuePairs ();
  1301.             break;
  1302.         case IDC_E_270:
  1303.             SetKeyValue (edit_entity, "angle", "270");
  1304.             SetFocus (g_qeglobals.d_hwndCamera);
  1305.             SetKeyValuePairs ();
  1306.             break;
  1307.         case IDC_E_315:
  1308.             SetKeyValue (edit_entity, "angle", "315");
  1309.             SetFocus (g_qeglobals.d_hwndCamera);
  1310.             SetKeyValuePairs ();
  1311.             break;
  1312.         case IDC_E_UP:
  1313.             SetKeyValue (edit_entity, "angle", "-1");
  1314.             SetFocus (g_qeglobals.d_hwndCamera);
  1315.             SetKeyValuePairs ();
  1316.             break;
  1317.         case IDC_E_DOWN:
  1318.             SetKeyValue (edit_entity, "angle", "-2");
  1319.             SetFocus (g_qeglobals.d_hwndCamera);
  1320.             SetKeyValuePairs ();
  1321.             break;
  1322.  
  1323.     case IDC_BTN_HIDE:
  1324.       ::PostMessage(g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CAMERATOGGLE, 0);
  1325.       break;
  1326.  
  1327.         case IDC_CHECK1:
  1328.         case IDC_CHECK2:
  1329.         case IDC_CHECK3:
  1330.         case IDC_CHECK4:
  1331.         case IDC_CHECK5:
  1332.         case IDC_CHECK6:
  1333.         case IDC_CHECK7:
  1334.         case IDC_CHECK8:
  1335.         case IDC_CHECK9:
  1336.         case IDC_CHECK10:
  1337.         case IDC_CHECK11:
  1338.         case IDC_CHECK12:
  1339.             GetSpawnFlags();
  1340.             SetFocus (g_qeglobals.d_hwndCamera);
  1341.             break;
  1342.  
  1343.  
  1344.         case IDC_E_PROPS: 
  1345.             switch (HIWORD(wParam))
  1346.             { 
  1347.             case LBN_SELCHANGE:
  1348.  
  1349.                 EditProp();
  1350.                 return TRUE; 
  1351.             }
  1352.             break;
  1353.  
  1354.         case IDC_E_LIST: 
  1355.        
  1356.             switch (HIWORD(wParam)) { 
  1357.             
  1358.             case LBN_SELCHANGE: 
  1359.             {
  1360.                 int iIndex;
  1361.                 eclass_t *pec;
  1362.                 
  1363.                 iIndex = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);    
  1364.                 pec = (eclass_t *)SendMessage(hwndEnt[EntList], LB_GETITEMDATA, 
  1365.                         iIndex, 0); 
  1366.             
  1367.                 UpdateSel(iIndex, pec);
  1368.  
  1369.                 return TRUE; 
  1370.                 break; 
  1371.             }
  1372.  
  1373.             case LBN_DBLCLK: 
  1374.                 CreateEntity ();
  1375.                 SetFocus (g_qeglobals.d_hwndCamera);
  1376.                 break; 
  1377.             } 
  1378.             break; 
  1379.  
  1380.  
  1381.             default: 
  1382.               return DefWindowProc( hwndDlg, uMsg, wParam, lParam ); 
  1383.         } 
  1384.  
  1385.         return 0;
  1386.     }
  1387.  
  1388.     return DefWindowProc (hwndDlg, uMsg, wParam, lParam);
  1389. }
  1390.  
  1391.